import { store } from '../index.js'
import iView from 'iview'

export default {
    state: {
        loadingCount: 0,
        loadingObj: {}
    },

    mutations: {
        showLoading() {
            if (this.state.loading.loadingCount <= 0) {
                iView.LoadingBar.finish()
                this.state.loadingObj = iView.Message.loading({
                    content: '发送请求中',
                    duration: 0
                });
            }
            this.state.loading.loadingCount++;
        },
        hideLoading() {
            this.state.loading.loadingCount--;
            if (this.state.loading.loadingCount <= 0) {
                iView.LoadingBar.finish()
                // console.log(this.state.loadingObj);
                this.state.loadingObj();
                // iView.Message.destroy();
            }
        }, setTitle(state, obj) {
            if (obj.name) {
                store.state.title = obj.name;
            }
        }
    }
}